﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web;

namespace DAL
{
    public class DataAccess
    {
        private string sqlConnectionString;

        public DataAccess()
        {
            Utility.XML.Xml configFile = new Utility.XML.Xml(System.Web.HttpContext.Current.Server.MapPath("AppConfig.xml"));
            sqlConnectionString = configFile.GetElementValue("UI", "SqlConnectionString");
        }

        public DataTable GetResultTable(string keyword, int page)
        {
            List<SqlParameter> paraList = new List<SqlParameter>();
            string keyword2 = keyword.Replace(" ", "%");
            paraList.Add(new SqlParameter("@Keyword", keyword2));
            paraList.Add(new SqlParameter("@Page", page));
            DataTable dt = Utility.Database.SqlServer.ExecuteSqlSelection(sqlConnectionString, "se_GetResultByKwPg", 
                paraList, CommandType.StoredProcedure);
            return dt;
        }

        //public int GetResultCount(string keyword)
        //{
        //    List<SqlParameter> paraList = new List<SqlParameter>();
        //    string keyword2 = keyword.Replace(" ", "%");
        //    paraList.Add(new SqlParameter("@Keyword", keyword2));
        //    DataTable dt = Utility.Database.SqlServer.ExecuteSqlSelection(sqlConnectionString, "se_GetResultCount",
        //        paraList, CommandType.StoredProcedure);
        //    return dt.Rows.Count;
        //}
    }
}
